home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / nihcl-30.lha / nihcl-3.0 / lib / Array_h.m4 < prev    next >
Text File  |  1990-05-19  |  3KB  |  103 lines

  1. /*$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/lib/RCS/Array_h.m4,v 3.0 90/05/20 00:18:58 kgorlen Rel $*/
  2.  
  3. /* Array_h.m4 -- template for declarations for generic array objects
  4.  
  5.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  6.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  7.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  8.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  9.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  10.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  11.  
  12. Author:
  13.     K. E. Gorlen
  14.     Bg. 12A, Rm. 2033
  15.     Computer Systems Laboratory
  16.     Division of Computer Research and Technology
  17.     National Institutes of Health
  18.     Bethesda, Maryland 20892
  19.     Phone: (301) 496-1111
  20.     uucp: uunet!nih-csl!kgorlen
  21.     Internet: kgorlen@alw.nih.gov
  22.     September, 1985
  23.  
  24. Function:
  25.  
  26. m4 macro template for the .h files for arrays of the specified
  27. fundamental type: char, int, short, long, unsigned, float, and double.
  28. For example, to generate the declarations for an array of chars:
  29.  
  30.     echo "ARRAYDECLARE(Arraychar,char,friend SubString;)" | m4 Array.h.m4 - >Arraychar.h
  31.  
  32. $Log:    Array_h.m4,v $
  33. Revision 3.0  90/05/20  00:18:58  kgorlen
  34. Release for 1st edition.
  35.  
  36. */
  37.  
  38. define(ARRAYDECLARE,
  39. ``#ifndef'' $1_H
  40. ``#define'' $1_H
  41.  
  42. ``#include'' "Collection.h"
  43. ``#include'' <malloc.h>
  44.  
  45. inline $2* REALLOC($2* ptr, unsigned size)
  46. {
  47.     return ($2*)realloc((char*)ptr,sizeof($2)*size);
  48. }
  49.  
  50. inline void DELETE($2* ptr) { free((char*)ptr); }
  51.  
  52. class $1: public Collection {
  53.     DECLARE_MEMBERS($1);
  54.     $2* v;
  55.     unsigned sz;
  56.     void AllocSizeErr() const;
  57.     void IndexRangeErr() const;
  58. // friends go here
  59.     $3
  60. protected:        // storer() functions for object I/O
  61.     virtual void storer(OIOofd&) const;
  62.     virtual void storer(OIOout&) const;
  63. public:
  64.     $1(unsigned size =DEFAULT_CAPACITY);
  65.     $1(const $1&);
  66.     ~$1();
  67.     $2& elem(int i)            { return v[i]; }
  68.     const $2& elem(int i) const    { return v[i]; }
  69.     bool operator!=(const $1& a) const { return !(*this==a); }
  70.     void operator=(const $1&);
  71.     bool operator==(const $1&) const;
  72.     $2& operator[](int i) {
  73.         if ((unsigned)i >= sz) IndexRangeErr();
  74.         return v[i];
  75.     }
  76.     $2 operator[](int i) const {
  77.         if ((unsigned)i >= sz) IndexRangeErr();
  78.         return v[i];
  79.     }
  80.     virtual unsigned capacity() const;
  81.     virtual int compare(const Object&) const;
  82.     virtual void deepenShallowCopy();
  83.     virtual void dumpOn(ostream& strm =cerr) const;
  84.     virtual unsigned hash() const;
  85.     virtual bool isEqual(const Object&) const;
  86.     virtual void printOn(ostream& strm =cout) const;
  87.     virtual void removeAll();
  88.     virtual void reSize(unsigned);
  89.     virtual unsigned size() const;
  90.     virtual void sort();
  91.     virtual const Class* species() const;
  92. private:                    // shouldNotImplement()
  93.     virtual Object* add(Object&);
  94.     virtual Object*& at(int);
  95.     virtual const Object *const& at(int) const;
  96.     virtual Object* doNext(Iterator&) const;
  97.     virtual unsigned occurrencesOf(const Object&) const;
  98.     virtual Object* remove(const Object&);
  99. };
  100.  
  101. ``#endif''
  102. )
  103.